package com.csproj.basic.repository;

import com.csproj.basic.domain.Area;
import com.csproj.basic.domain.Container;
import com.csproj.basic.domain.Warehouse;
import com.csproj.basic.repository.custom.AreaRepositoryCustom;
import com.csproj.basic.repository.custom.ContainerRepositoryCustom;
import org.springframework.stereotype.Repository;

import org.springframework.data.jpa.repository.*;

import java.util.List;
import java.util.concurrent.atomic.AtomicReferenceArray;


/**
 * Spring Data JPA repository for the Area entity.
 */
@SuppressWarnings("unused")
@Repository
public interface AreaRepository extends JpaRepository<Area, String>, AreaRepositoryCustom {
    /**
     * 根据ids查询区域信息
     * @author LM
     * @date   2018-09-18
     * @param ids
     * @return
     */
    @Query(" from Area where id in (?1) ")
    List<Area> findByIds(String[] ids);


    /**
     * 根据ID删除数据
     * @author LM
     * @date   2018-09-18
     * @param id 机构id
     */
    @Modifying
    @Query("UPDATE Area SET deletedFlag = 1 where id = ?1")
    void delete(String id);

    /**
     * 根据ID删除数据
     * @author LM
     * @date   2018-09-18
     * @param id 机构id
     */
    @Query(" from Area where deletedFlag = 0 and id = ?1")
    Area findById(String id);

    Area findFirstByCodeAndDeletedFlagIsFalse(String code);

    Area findFirstByWarehouseIdAndSiteIdAndDeletedFlagIsFalseAndBlockFlagIsTrue(String wareHouseId,String siteId);

    Area findFirstByWarehouseIdAndSiteIdAndDeletedFlagIsFalseAndUnblockFlagIsTrue(String wareHouseId,String siteId);
    /**
     * 根据机构ids，批量删除区域信息
     * @param ids
     */
    @Modifying
    @Query(" update Area set deletedFlag = 1 where id in (?1) ")
    void deleteIds(String[] ids);
}
